<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>并集_差集_交集</title>
</head>

<body>

</body>
<script>
  "use strict"; {
    let a = new Set([1, 2, 4, 2, 5, 8]);
    let b = new Set([3, 4, 8, 9, 10, 2]);
    // 并集
    let res0 = Array.from(new Set([...a, ...b]));
    console.table(res0);
    // 差集
    let res1 = new Set([...a].filter((value, index, arr) => {
      return !b.has(value);
    }));
    console.table(Array.from(res1));
    // 交集
    let res2 = new Set([...a].filter((value, index, arr) => {
      return b.has(value);
    }));
    console.table(Array.from(res2));
  };
</script>

</html>